Skip to content

fix: read /source and editor files as UTF-8 - #2432

Merged
rolandwalker merged 1 commit into
dbcli:mainfrom
pcbeingused333:fix/source-editor-utf8
Nov 14, 2026
Merged

rolandwalker merged 1 commit into
dbcli:mainfrom
pcbeingused333:fix/source-editor-utf8

Conversation

@pcbeingused333

Copy link
Copy Markdown
Contributor

Follow-up to #2429: the same locale-encoding bug in the two remaining read paths (/source and the \e editor file).

Description

/source <file> (execute_from_file in client_commands.py) and the \e <file> editor read (open_external_editor in io_commands.py) opened the file with the locale's default encoding. Under a non-UTF-8 locale (Windows cp1252/cp932, LANG=C) a UTF-8 SQL file containing non-ASCII text is mis-decoded or rejected. The config and history files already pass encoding='utf-8'; these two open() calls were missing it.

Fix: pass encoding='utf-8' in both places, plus a changelog entry.

Tests: two new tests run the code in a subprocess with -X warn_default_encoding -W error::EncodingWarning, which fails on main (EncodingWarning: 'encoding' argument not specified) and passes with the fix. The existing open mocks in test_client_commands.py now accept the extra keyword.

Disclosure: this change was prepared with the help of an AI coding assistant (Claude); the submitter is responsible for it.

Checklist

  • I added this contribution to the changelog.md file.
  • I added my name to the mycli/AUTHORS.txt file (or it's already there).
  • ruff check and ruff format --check pass on the touched files; mypy not run (only an encoding keyword was added).

/source and the \e editor file were opened with the locale default encoding, so UTF-8 SQL files were mis-decoded or rejected under non-UTF-8 locales (Windows cp1252/cp932, LANG=C). Pass encoding='utf-8', matching the config and history files.
@rolandwalker

Copy link
Copy Markdown
Contributor

Thanks again! Windows improvements greatly appreciated. The only thing I could ask is for the changelog entry to be more concise.

@rolandwalker
rolandwalker merged commit 3242d19 into dbcli:main Nov 14, 2026
13 checks passed
@rolandwalker

Copy link
Copy Markdown
Contributor

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants